<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <script type="text/javascript">
  	var req;
  	function validate(){
  		var username = document.getElementById("username").value;
  		var url = "validatePara?username="+username;
  		if(window.XMLHttpResquest){
  			req = new XMLHttpResquest();
  		}else if(window.ActiveXObject){
  			req = new ActiveXObject("Microsoft.XMLHTTP");
  		}
  		req.open("GET", url, true);
  		req.onreadystatechange = callback;
  		req.send(null);
  	}
  	
  	function callback(){
  		if(req.readyState == 4){
  			if(req.status == 200){
  				var msg = req.responseXML.getElementsByTagName("msg")[0];
  				setMsg(msg.childNodes[0].nodeValue);
  			}
  		}
  	}
  	
  	function setMsg(msg){
  		if(msg == "exist"){
  			document.getElementById("usermsg").innerHTML = "<font color='red'>exist</font>";
  		} else {
  			document.getElementById("usermsg").innerHTML = "<font color='yellow'>ok</font>";
  		}
  	}
  	
  	function clearText() {
  		document.getElementById("usermsg").innerHTML = "";
  	}
  </script>

  </head>
  
  <body>
    <table>
    	<tr>
    		<td>name:</td>
    		<td><input type="text" id="username" name="username" onfocus="clearText()" onblur="validate()"/></td>
    		<td><div id="usermsg"></div></td>
    	</tr>
    </table>
  </body>
</html>
